package org.zhouhe.web.tag.function;

public class PanelSubmitFunction {
	private String funName;
	private String url;
	public PanelSubmitFunction(String funName, String url) {
		this.funName = funName;
		this.url = url;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("\r\n  function "+ funName +"(btn){");
		sb.append("\r\n    var data = {};");
		sb.append("\r\n    var array = $(btn).closest('form').serializeArray();");
		sb.append("\r\n    $(array).each(function(i, item){");
		sb.append("\r\n      if(item && item.name != '' && item.value != ''){");
		sb.append("\r\n        data[item.name] = item.value;");
		sb.append("\r\n      }");
		sb.append("\r\n    });");
		sb.append("\r\n    $('#sp_grid').datagrid({'url': '"+ url +"', 'queryParams':data, 'pageNumber':1}); ");
		sb.append("\r\n  }");
		return sb.toString();
	}
}
